//
//  DFStatuesOriginalView.swift
//  新浪微博
//
//  Created by dafei on 16/5/26.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit
import SnapKit


//设置对齐的边距
let StatuesCelMargin: CGFloat = 8

class DFStatuesOriginalView: UIView {

    var statuesViewModel: DFStatuesViewModel? {
    
        didSet {
            //绑定数据
//            let url = NSURL(string: statuesViewModel?.statues?.user?.profile_image_url ?? "")
            headIcon.sd_setImageWithURL(statuesViewModel?.headImageURL)
            nameLabel.text = statuesViewModel?.statues?.user?.name
            timeLabel.text = statuesViewModel?.statues?.created_at
            sourceLabel.text = statuesViewModel?.statues?.source
            contenLabel.text = statuesViewModel?.statues?.text
        
            //认真图片
//           verifiedImageView.image = statuesViewModel.
            mbrankImageView.image = statuesViewModel?.mbrankImage
            verifiedImageView.image = statuesViewModel?.veritiedImage
            
            
        }
    
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.yellowColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置UI界面
    private func setupUI() {
        addSubview(headIcon)
        addSubview(verifiedImageView)
        addSubview(nameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contenLabel)
        
        //设置约束
        headIcon.snp_makeConstraints { (make) in
            
            make.top.left.equalTo(self).offset(StatuesCelMargin)
            make.height.equalTo(40)
            make.width.equalTo(40)
            
        }
        
        verifiedImageView.snp_makeConstraints { (make) in
            make.right.bottom.equalTo(headIcon)
            
        }
        
        nameLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(headIcon.snp_top)
            make.left.equalTo(headIcon.snp_right).offset(StatuesCelMargin)
            
        }
        
        mbrankImageView.snp_makeConstraints { (make) in
            make.top.equalTo(headIcon.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatuesCelMargin)
            
        }
        
        timeLabel.snp_makeConstraints { (make) in
            make.left.equalTo(headIcon.snp_right).offset(StatuesCelMargin)
            make.bottom.equalTo(headIcon.snp_bottom)
            
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            make.left.equalTo(timeLabel.snp_right).offset(StatuesCelMargin)
            make.bottom.equalTo(headIcon.snp_bottom)
            
        }
        
        contenLabel.snp_makeConstraints { (make) in
            make.top.equalTo(headIcon.snp_bottom).offset(StatuesCelMargin)
            make.left.equalTo(headIcon.snp_left)
        }
        
        
    
    
    }
    
    
    //懒加载
    private lazy var headIcon: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var verifiedImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    private lazy var timeLabel: UILabel = UILabel(title: "13:16", font: 10, textColor: UIColor.darkGrayColor())
    private lazy var sourceLabel: UILabel = UILabel(title: "王大锤", font: 10, textColor: UIColor.darkGrayColor())
    
    private lazy var nameLabel: UILabel = UILabel(title: "杜雷", font: 14, textColor: UIColor.darkGrayColor())
    
    private lazy var contenLabel: UILabel = UILabel(title: "我是王大锤,我为自己带盐,我是王大锤,我为自己带盐,我是王大锤,我为自己带盐,我是王大锤,我为自己带盐我是王大锤,我为自己带盐,我是王大锤,我为自己带盐,我是王大锤,我为自己带盐我是王大锤", font: 14, textColor: UIColor.darkGrayColor(),alignment: .Left)
    
    

}
